﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Register Src="~/Views/Category/Image.ascx" TagName="image" TagPrefix="uc" %>
<%@ Register Src="~/Views/Shared/Checkbox.ascx" TagName="checkbox" TagPrefix="uc" %>

<%
    int lang = (int)ViewData["Language"];
    VietImage.Models.Lightbox lightbox = (VietImage.Models.Lightbox)ViewData["Lightbox"];
    int count = 0;
    Double h = 0;
    if (lightbox != null && lightbox.Images != null && lightbox.Images.Count > 0)
    {
        count = lightbox.Images.Count;
        h = ((Double)count / 2) + 0.5;
    }
    else
    {
        return;
    }
%>

<div id="lightboxcontrol_control">
<%
    if (Request["opt"] == "Detail")
    {
%>
    <div class="left">
        <div class="left"><span style="border-bottom: 1px #FFF dotted;">Xem ảnh dạng</span> :</div>
        <div class="left">
            <%= Html.ActionLink("Thumbnail", "Index", "Lightbox", new { id = lightbox.ID, opt = "Thumbnail" }, null)%> 
        </div>
        <div class="left">|</div> 
        <div class="left">
            <%= Html.ActionLink("Chi tiết", "Index", "Lightbox", new { id = lightbox.ID, opt = "Detail" }, new { @class = "active" })%>
        </div>
        <div class="clear"></div>
    </div>
<%
    }
    else
    {
%>
    <div class="left">
        <div class="left"><span style="border-bottom: 1px #FFF dotted;">Xem ảnh dạng</span> :</div>
        <div class="left">
            <%= Html.ActionLink("Thumbnail", "Index", "Lightbox", new { id = lightbox.ID, opt = "Thumbnail" }, new { @class = "active" })%> 
        </div>
        <div class="left">|</div> 
        <div class="left">
            <%= Html.ActionLink("Chi tiết", "Index", "Lightbox", new { id = lightbox.ID, opt = "Detail" }, null)%>
        </div>
        <div class="clear"></div>
    </div>
<%
    }
%>
    <div class="right">
    <div class="left"><span id="selectall">Chọn tất cả<img src="/Content/Images/checkall.png" /></span></div>
    <div class="left"><span id="deselectall">Bỏ chọn<img src="/Content/Images/x.png" /></span></div>
    <div class="left"><span id="removefromlightbox">Xóa khỏi Lightbox<img src="/Content/Images/x.png" /></span></div>
    <div class="left"><span id="downloadimages">Download Images<img src="/Content/Images/cart.png" /></span></div>
    <div class="clear"></div>    
    <div class="left">
        <div class="left" id="copytolightbox" style="cursor: pointer;">Chép vào Lightbox</div>
<%
    List<VietImage.Models.Lightbox> myLightboxes = (List<VietImage.Models.Lightbox>)ViewData["LightboxList"];
    if (myLightboxes != null)
    {
        myLightboxes.Remove(lightbox);
%>
        <div id="cmbcopytolightbox" class="combobox" value="">
            <div class="combobox_selected"></div>
            <div class="combobox_button"></div>
            <div class="combobox_items">
<%
        foreach (VietImage.Models.Lightbox lb in myLightboxes)
        {
%>
                <div class="combobox_item" value="<%= lb.ID %>" ><%= lb.Name%></div>
<% 
        }
%>
            </div>
        </div>
<%    
    }
    else
    {
%>
            <div class="left">Bạn chưa có lightbox nào</div>
<%
    }
%>
        <div class="clear"></div>    
    </div>
    <div class="clear"></div>    
    </div>
    <div class="clear"></div>    
</div>






    <div id="lightboxdetail">
<div id="imagelist">
<%
    if (Request["opt"] == "Detail")
    {
%>
    <div id="imagescroller" class="scrollery scroller">
        <div style="top: 20px;" class="scrollbar">
            <div class="scrollbar_end"></div>
            <div class="scrollbar_thumb"><div class="scrollbar_thumb_end"></div></div>
        </div>
        <div class="scroller_collumheader">
            <div class="imgdetail_check">Chọn</div>
            <div class="imgdetail_name">Tên ảnh</div>
            <div class="imgdetail_img">Hình ảnh</div>
            <div class="imgdetail_downloadthumbnail">Tải thumbnail</div>
            <div class="imgdetail_downloadsmall">Tải ảnh nhỏ</div>
            <div class="imgdetail_downloadfullsize">Tải ảnh gốc</div>
            <div class="clear"></div>
        </div>
        <div style="top: 20px; height: " class="scroller_view">
            <div class="scroller_panel">
<%
        foreach (VietImage.Models.Image img in lightbox.Images)
        {
            checkbox1.ID = "chkimg" + img.ID;
            checkbox2.ID = "chkimgthumbnail" + img.ID;
            checkbox3.ID = "chkimgsmall" + img.ID;
            checkbox4.ID = "chkimgfull" + img.ID;
%>
                <div class="imgdetail_row">
                    <div class="imgdetail_check"><uc:checkbox Class="chkimg" Style="float: none; margin: auto;" ID="checkbox1" runat="server"/></div>
                    <div class="imgdetail_name"><label for="<%=checkbox1.ID %>"><%= img.GetDetail(lang).Name %></label></div>
                    <div class="imgdetail_img"><img src="/Image/Display/<%= img.ID %>" alt="<%= img.GetDetail(lang).Name %>" /></div>
                    <div class="imgdetail_downloadthumbnail"><uc:checkbox Class="chkimgthumbnail" Style="float: none; margin: auto;" Disabled="true" ID="checkbox2" runat="server"/></div>
                    <div class="imgdetail_downloadsmall"><uc:checkbox Class="chkimgsmall" Style="float: none; margin: auto;" Disabled="true" ID="checkbox3" runat="server"/></div>
                    <div class="imgdetail_downloadfullsize"><uc:checkbox Class="chkimgfull" Style="float: none; margin: auto;" Disabled="true" ID="checkbox4" runat="server"/></div>
                    <div class="clear"></div>
                </div>
<%
        }
%>
            </div>
        </div>
        <div class="clear"></div>
    </div>
<%
    }
    else
    {
%>
    <div id="imagescroller" style="margin: auto; width: 890px" class="scrollerx scroller">
        <div style="margin-left: 0px; width: 400px;" class="scrollbar">
            <div class="scrollbar_end"></div>
            <div class="scrollbar_thumb"><div class="scrollbar_thumb_end"></div></div>
        </div>
        <div class="clear"></div>
        <div class="scroller_view" style="height: 530px; width: 890px;">

<% 
        int itemwidth = 230;
        int half = (int)h;
%>
            <div class="scroller_panel" style="height: 530px; width: <%= half * itemwidth %>px">
<%
        for (int i = 0; i < count; )
        {
            img1.ViewData["Parent"] = lightbox;
            img1.ViewData["Image"] = lightbox.Images[i++];
%>
                <div class="imagelistcolumn">
                    <uc:image ID="img1" runat="server" />
<%
            if (i < count)
            {
                img2.ViewData["Parent"] = lightbox;
                img2.ViewData["Image"] = lightbox.Images[i++];
%>
                    <uc:image ID="img2" runat="server" />
<%
            } 
%>
                </div>
<%
        }
%>
                <div class="clear"></div>
            </div>
        </div>
    </div>
	<div class="clear"></div>
<%
    }
%>

</div>
    </div>
<script>
    $(document).ready(function (e) {
        $(".chkimg").bind("changed", function () {
            if ($(this).attr("checked")) {
                $(this).parent("div").parent(".imgdetail_row").find(".chkimgthumbnail, .chkimgsmall, .chkimgfull").removeAttr("disabled").trigger("check");
            } else {
                $(this).parent("div").parent(".imgdetail_row").find(".chkimgthumbnail, .chkimgsmall, .chkimgfull").trigger("uncheck").attr("disabled", "");
            }
        });
    });
</script>